package com.nettest.service.system;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nettest.dao.system.DictionaryDao;
import com.nettest.entity.BaseEntity;
import com.nettest.entity.system.Dictionary;
import com.nettest.pojo.Page;
import com.nettest.service.BaseIbatisService;

@Service
@Transactional
public class DictionaryService extends BaseIbatisService {
	@Autowired
	private DictionaryDao dictionaryDao;

	public BaseEntity save(BaseEntity entity) throws Exception {
		return dictionaryDao.save((Dictionary)entity);
	}

	public void delete(Long id) throws Exception {
		dictionaryDao.delete(id);
	}

	public Dictionary get(Serializable id) throws Exception {
		return dictionaryDao.get(id);
	}

	public List<Dictionary> getDicByCategory(String category) {
		List<Dictionary> list = dictionaryDao.findBySql("select d from Dictionary d where d.category = ? order by d.category, d.sort",category);
		return list;
	}

	public List<Dictionary> findAllDictionary() {
		List<Dictionary> list = dictionaryDao.findBySql("select d from Dictionary d order by d.category, d.sort");
		return list;
	}

	public Page findByPageDictionary(Page page) throws Exception { 
        page.setTotalProperty((Integer)queryForObject("findByCount", page)); 
        page.setPageProperty(page); 
        page.setRoot(queryForList( 
                "findByPage", page)); 
        return page; 
    } 
}
